-
-
Notifications
You must be signed in to change notification settings - Fork 26
Edits to MC lecture #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Edits to MC lecture #105
Conversation
✅ Deploy Preview for taupe-gaufre-c4e660 ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
|
@HumphreyYang , could you please use the logic in ψ = (0.0, 0.2, 0.8) # Initial condition
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection='3d')
ax.set(xlim=(0, 1), ylim=(0, 1), zlim=(0, 1),
xticks=(0.25, 0.5, 0.75),
yticks=(0.25, 0.5, 0.75),
zticks=(0.25, 0.5, 0.75))
x_vals, y_vals, z_vals = [], [], []
for t in range(20):
x_vals.append(ψ[0])
y_vals.append(ψ[1])
z_vals.append(ψ[2])
ψ = ψ @ P
ax.scatter(x_vals, y_vals, z_vals, c='r', s=60)
ax.view_init(30, 210)
mc = qe.MarkovChain(P)
ψ_star = mc.stationary_distributions[0]
ax.scatter(ψ_star[0], ψ_star[1], ψ_star[2], c='k', s=60)
plt.show()in the two code cells that follow it --- see https://63fbdf37cab3e348c2918816--taupe-gaufre-c4e660.netlify.app/markov_chains.html Perhaps you can unify these three code cells at least partially by writing a function that updates according to Then you can extract coordinates for the plots. Thanks. |
|
Many thanks @jstac for your review. I have integrated these code blocks with a function for simulating Please let me know if it needs further changes. |
| Let's pick an initial distribution $\psi$ and trace out the sequence of distributions $\psi P^t$. | ||
|
|
||
| First, we write a function to simulate the sequence of distributions for `n` period | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HumphreyYang I suggest we avoid the use of the word "simulate" here and in the name of the function, since there is no randomness involved. (We are just iterating on the deterministic vector difference equation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks @jstac for picking this up. I have changed the function name to iterate_ψ.
|
Thanks @HumphreyYang for your quick response and nice update. Please see the comment above. |
|
Nice work @HumphreyYang . Merging. |
| if ψ is not None: | ||
| X_0 = qe.random.draw(np.cumsum(ψ)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jstac,
Thanks for reminding me about the consistency in notation. It helps a lot to keep the code clear.
I just noticed that you were avoiding the use of ψ_0 in this function for initial distribution. I can see why this is preferred given no other $\psi$s are used, so _0 is redundant, but I also think it would be good if the notation for initial distributions is treated the same throughout this lecture. Please kindly let me know what you think about changing all initial distributions to ψ_0.
Many thanks in advance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @HumphreyYang , I changed that one to be consistent with the mathematics above.
But you are right --- the code is now inconsistent with code that follows. Shall we change it back and then change the maths above it to use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, I appreciate you raising this. Getting all the small things right is essential to creating a great lecture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @HumphreyYang , I changed that one to be consistent with the mathematics above.
But you are right --- the code is now inconsistent with code that follows. Shall we change it back and then change the maths above it to use ψ0 instead of ψ?
Many thanks @jstac; I think changing to
No description provided.